package com.cskaoyan.controller.backstagecontroller;

import com.cskaoyan.bean.bo.ObjectStorageBo;
import com.cskaoyan.bean.pojo.ObjectStorage;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.StorageListVo;
import com.cskaoyan.service.ObjectStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("admin/storage")

public class ObjectStorageController {
    @Autowired
    ObjectStorageService objectStorageService;

    @RequestMapping("list")
    public BaseRespVo selectStorageListVo(ObjectStorageBo objectStorageBo) {
        StorageListVo storageListVo = objectStorageService.selectStorageListVo(objectStorageBo);
        return BaseRespVo.ok(storageListVo);
    }

    @RequestMapping("create")
    public BaseRespVo uploadFile(MultipartFile file) {
        ObjectStorage objectStorage = objectStorageService.uploadFile(file);
        return BaseRespVo.ok(objectStorage);
    }

    @RequestMapping("update")
    public BaseRespVo updateObjectStorage(ObjectStorage storage) {
        ObjectStorage objectStorage = objectStorageService.updateObjectStorage(storage);
        return BaseRespVo.ok(objectStorage);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteObjectStorage(ObjectStorage storage) {
        objectStorageService.deleteObjectStorage(storage);
        return BaseRespVo.ok();
    }
}
